package com.skg.tools;

import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemProperties;

import android.util.Log;
import android.view.Gravity;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.Toast;

//todo tangyue-20221207
//import com.skg.services.manager.SkgSourceManager;
//import com.skg.services.manager.SkgTouchManager;
import com.skg.tools.calculator.CaculatorWindowCtl;
import com.skg.tools.clean.SkgClean;
import com.skg.tools.lock.NumberPassWord;
import com.skg.tools.lock.TouchLockImage;
import com.skg.tools.lock.TouchLockView;
import com.skg.tools.recorder.SkgRecordLayout;
import com.skg.tools.spotlight.SpotActivity;
import com.skg.tools.spotlight.SpotLayout;
import com.skg.tools.timer.TimerLayout;
import com.skg.tools.view.DialogLayout;
import com.skg.tools.temperature.TemperatureLayout;
import android.view.View;
import android.view.MotionEvent;
import android.os.Build;
import android.content.ContentResolver;
import android.provider.Settings;
import com.skg.tools.protectburnview2.ProtectBurnView2;
import static android.view.View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;

public class MyWindowManager {
    private static TouchLockImage mLockViewLeft, mLockViewRight;
    private static TouchLockView mTouchLockView;
    private static LayoutParams layoutParamsTouchLock, layoutParamsLockLeft, layoutParamsLockRight;
    private static WindowManager mWindowManager;
    private static SkgClean sMSkgClean;
    private static LayoutParams skgCleanParams, mSpotLightParams, backlightCoverParams;
    private static SpotLayout mSpotLayout;
    private static LayoutParams mDialogParams;
    private static LayoutParams mNumberParams;
    private static NumberPassWord mBacklightView;
    private static View mNumberPassWord;
    private static View mCirclePassWord;
    private static View mNoPassword;
    private static SkgRecordLayout mRecordLayout;
    private static TimerLayout mTimerLayout;
    private static LayoutParams skgTimerParams;
    private static LayoutParams skgRecordParams;
    private static TemperatureLayout temperatureLayout;
    private static LayoutParams layoutParamsTemperature;

    private static View backlightCoverView;

    private static boolean isShowSpotLight = false;
    private static ProtectBurnView2 mProtectBurnView;
    private static LayoutParams mProtectBurnViewParams;

    public static void createBacklightCover(Context context) {
        WindowManager windowManager = getWindowManager(context);
        if (backlightCoverView == null) {
            backlightCoverView = new View(context);
            backlightCoverView.setOnTouchListener(new View.OnTouchListener() {
                float x = 0, y = 0;
                boolean move_gone = false;
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    int action = event.getAction();
                    switch(action){
                        case MotionEvent.ACTION_DOWN:
                            x = event.getRawX();
                            y = event.getRawY();
                            move_gone = false;
                            break;
                        case MotionEvent.ACTION_MOVE:
                            float xx = event.getRawX() - x;
                            float yy = event.getRawY() - y;
                            double distance = Math.sqrt(Math.pow(xx, 2) + Math.pow(yy, 2));
                            if(distance > 70 && !move_gone){
                                move_gone = true;
                            }
                            break;
                        case MotionEvent.ACTION_UP:
                            break;
                    }
                    return true;
                }
            });
            if (backlightCoverParams == null) {
                backlightCoverParams = new LayoutParams();
                backlightCoverParams.format = PixelFormat.RGBA_8888;
                backlightCoverParams.flags = LayoutParams.FLAG_NOT_FOCUSABLE;
                backlightCoverParams.type = LayoutParams.TYPE_SYSTEM_ALERT;
                backlightCoverParams.width = LayoutParams.MATCH_PARENT;
                backlightCoverParams.height = LayoutParams.MATCH_PARENT;
            }
            windowManager.addView(backlightCoverView, backlightCoverParams);
        }
    }

    public static void removeBacklightCover(Context context) {
        if (backlightCoverView != null) {
            WindowManager windowManager = getWindowManager(context);
            windowManager.removeView(backlightCoverView);
            backlightCoverView = null;
        }
    }


    public static void createSkgClean(Context context) {
        WindowManager windowManager = getWindowManager(context);
        if (sMSkgClean == null) {
            sMSkgClean = new SkgClean(context);
            if (skgCleanParams == null) {
                skgCleanParams = new LayoutParams();
                skgCleanParams.type = LayoutParams.TYPE_PHONE;
                skgCleanParams.format = PixelFormat.RGBA_8888;
                skgCleanParams.flags = LayoutParams.FLAG_NOT_FOCUSABLE;
                skgCleanParams.type = LayoutParams.TYPE_PHONE;
                skgCleanParams.width = LayoutParams.MATCH_PARENT;
                skgCleanParams.height = LayoutParams.MATCH_PARENT;
            }
            windowManager.addView(sMSkgClean, skgCleanParams);
        }
    }

    public static void removeSkgClean(Context context) {
        if (sMSkgClean != null) {
            WindowManager windowManager = getWindowManager(context);
            windowManager.removeView(sMSkgClean);
            sMSkgClean = null;
        }
    }


    private static WindowManager getWindowManager(Context context) {
        if (mWindowManager == null) {
            mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        }
        return mWindowManager;
    }

    private static CaculatorWindowCtl mCaculatorWindowCtl;

    public static void createCaculator(Context context, int mode) {
        if (mCaculatorWindowCtl == null) {
            mCaculatorWindowCtl = new CaculatorWindowCtl(context, mode);
            mCaculatorWindowCtl.createView();
            //getWindowManager(context).setViewDisplay(WindowManager.VIEW_CACULATOR, true);
        }
    }

    public static void removeCaculator(Context context) {
        if (mCaculatorWindowCtl != null) {
            mCaculatorWindowCtl.removeView();
            //getWindowManager(context).setViewDisplay(WindowManager.VIEW_CACULATOR, false);
            mCaculatorWindowCtl = null;
        }
    }

    public static void createSpotLight(Context context) {
        Intent intent = new Intent();
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setClass(context, SpotActivity.class);
        context.startActivity(intent);
    }

    public static void createSpotLight1(Context context) {
        /*Intent intent = new Intent();
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setClass(context , SpotActivity.class);
        context.startActivity(intent);*/

        final WindowManager windowManager = getWindowManager(context);
        mSpotLayout = new SpotLayout(context);
        if (mSpotLightParams == null) {
//            mSpotLightParams = new LayoutParams();
//            mSpotLightParams.format = PixelFormat.RGBA_8888;
//            mSpotLightParams.type = LayoutParams.TYPE_SYSTEM_ALERT
//                    | LayoutParams.TYPE_SYSTEM_OVERLAY;
//            mSpotLightParams.flags = LayoutParams.FLAG_LAYOUT_ATTACHED_IN_DECOR | LayoutParams.FLAG_FULLSCREEN;

            mSpotLightParams = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, // 使用合适的窗口类型
                    WindowManager.LayoutParams.FLAG_FULLSCREEN, // 设置窗口标志
                    PixelFormat.TRANSLUCENT);

            // 隐藏状态栏和导航栏的标志
            mSpotLightParams.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; // 全屏显示，隐藏状态栏
            mSpotLightParams.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

            WindowManager mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            Point point = new Point();
            mWindowManager.getDefaultDisplay().getRealSize(point);
            int mWindowWidth = point.x; //3840
            int mWindowHeight = point.y; //2160

            mSpotLightParams.width = mWindowWidth;
            mSpotLightParams.height = mWindowHeight;
        }
        mSpotLayout.setCallBack(new SpotLayout.OnSpotExitCallBack() {
            @Override
            public void onExit() {
                if (mSpotLayout != null) {
                    windowManager.removeView(mSpotLayout);
                    isShowSpotLight = false;
                }
            }
        });
        if(!isShowSpotLight){
            windowManager.addView(mSpotLayout, mSpotLightParams);
            isShowSpotLight = true;
        }
    }

    public static void createDialogLayout(DialogLayout mDialog, Context context) {
        WindowManager windowManager = getWindowManager(context);
        if (mDialog == null) {
            return;
        }
        if (mDialogParams == null) {
            mDialogParams = new LayoutParams();
            mDialogParams.type = LayoutParams.TYPE_PHONE;
            mDialogParams.format = PixelFormat.RGBA_8888;
            mNumberParams.flags = LayoutParams.FLAG_SECURE;

            mDialogParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
                    | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
            mDialogParams.width = LayoutParams.MATCH_PARENT;
            mDialogParams.height = LayoutParams.MATCH_PARENT;
            mDialogParams.gravity = Gravity.CENTER;
        }
        windowManager.addView(mDialog, mDialogParams);
    }

    private static String sourceBeforeLock = "ANDROID";

    public static final String SCREEN_LOCK_GRAPHIC_PASSWORD = "screen_lock_graphic_password";
    public static final String SCREEN_LOCK_NUMBER_PASSWORD = "screen_lock_number_password";
    public static final String SCREEN_LOCK_SWITCH = "screen_lock_switch";
    public static final String SCREEN_LOCK_TYPE = "screen_lock_type";

    public static void createNumberPassWord(Context context, int mode) {
        WindowManager windowManager = getWindowManager(context);
        View mView = null;
        // ContentResolver resolver = context.getApplicationContext().getContentResolver();
        // int lockType = Integer.parseInt(Settings.Global.getString(resolver, SCREEN_LOCK_TYPE));
        // boolean lockSwitch = Boolean.parseBoolean(Settings.Global.getString(resolver, SCREEN_LOCK_SWITCH));

        if (mode == NumberPassWord.PASSMODE_LOCK_BACKLIGHT) {
            if (mBacklightView == null) {
                mBacklightView = new NumberPassWord(context, null);
            } else {
                return;
            }
            mView = mBacklightView;
        } else {
            if (mNumberPassWord == null) {
                mNumberPassWord = new NumberPassWord(context, null);
            }
            mView = mNumberPassWord;
        }
        if (mNumberParams == null) {
            mNumberParams = new LayoutParams();
            mNumberParams.format = PixelFormat.RGBA_8888;
            mNumberParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
                    | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
            mNumberParams.width = LayoutParams.MATCH_PARENT;
            mNumberParams.height = LayoutParams.MATCH_PARENT;
        }
        windowManager.addView(mView, mNumberParams);
    }

    public static void removeDialogLayout(DialogLayout mDialog, Context context) {
        if (mDialog != null) {
            WindowManager windowManager = getWindowManager(context);
            windowManager.removeView(mDialog);
        }
    }

    public static void removeNumberPassWord(Context context) {
        removeNumberPassWord(context, NumberPassWord.PASSMODE_LOCK_NORMAL);
    }

    public static void removeNumberPassWord(Context context, int mode) {

        View mView = null;
        ContentResolver resolver = context.getApplicationContext().getContentResolver();
//		int lockType = Integer.parseInt(Settings.Global.getString(resolver, SCREEN_LOCK_TYPE));
        int lockType = Integer.parseInt(SystemProperties.get(SCREEN_LOCK_SWITCH));

        if (mode == NumberPassWord.PASSMODE_LOCK_BACKLIGHT) {
            mView = mBacklightView;
        } else {
            mView = mNumberPassWord;
        }
        if (mView != null) {
            WindowManager windowManager = getWindowManager(context);

            if (mView instanceof NumberPassWord) {
                ((NumberPassWord) mView).closePassword();
            }
            windowManager.removeView(mView);

            if (mode == NumberPassWord.PASSMODE_LOCK_BACKLIGHT) {
                mBacklightView = null;
            } else {
                mNumberPassWord = null;
                mCirclePassWord = null;
                mNoPassword = null;
            }
            if (mNumberPassWord == null && mBacklightView == null) {
                //windowManager.setViewDisplay(WindowManager.VIEW_PASSWORD, false);
            }
        }
        Intent intent = new Intent("com.skg.menu_ui.system.show_sidebar");
        intent.setPackage("com.skg.menu_ui");
        intent.putExtra("mode", 0);
        context.sendBroadcast(intent);
    }

    public static void removeCountDown(Context context) {
        if (mTimerLayout != null) {
            WindowManager windowManager = getWindowManager(context);
            windowManager.removeView(mTimerLayout);
            //windowManager.setViewDisplay(WindowManager.VIEW_TIMER, false);
            mTimerLayout = null;
        }
        if(skgTimerParams != null){
            skgTimerParams = null;
        }
    }

    public static void createCountDown(Context context) {
        WindowManager windowManager = getWindowManager(context);
        if (mTimerLayout == null) {
            mTimerLayout = new TimerLayout(context);
            if (skgTimerParams == null) {
                skgTimerParams = new LayoutParams();
                skgTimerParams.format = PixelFormat.RGBA_8888;
                skgTimerParams.flags = LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
                skgTimerParams.type = LayoutParams.TYPE_APPLICATION_OVERLAY;
                skgTimerParams.width = LayoutParams.WRAP_CONTENT;
                skgTimerParams.height = LayoutParams.WRAP_CONTENT;
                skgTimerParams.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
                skgTimerParams.windowAnimations = 0;
            }
            mTimerLayout.setParams(skgTimerParams);
            windowManager.addView(mTimerLayout, skgTimerParams);
            //windowManager.setViewDisplay(WindowManager.VIEW_TIMER, true);
        }
    }

    public static void createRecord(Context context) {
        WindowManager windowManager = getWindowManager(context);
        if (mRecordLayout == null) {
            mRecordLayout = new SkgRecordLayout(context);
            if (skgRecordParams == null) {
                skgRecordParams = new LayoutParams();
                skgRecordParams.format = PixelFormat.RGBA_8888;
                skgRecordParams.flags = LayoutParams.FLAG_NOT_FOCUSABLE;
                skgRecordParams.type = WindowManager.LayoutParams.TYPE_PHONE;
                skgRecordParams.width = LayoutParams.WRAP_CONTENT;
                skgRecordParams.height = LayoutParams.WRAP_CONTENT;
            }
            mRecordLayout.setParams(skgRecordParams);
            windowManager.addView(mRecordLayout, skgRecordParams);
            //windowManager.setViewDisplay(WindowManager.VIEW_RECOND, true);
        }
    }

    public static void removeRecord(Context context) {
        if (mRecordLayout != null) {
            WindowManager windowManager = getWindowManager(context);
            windowManager.removeView(mRecordLayout);
            //windowManager.setViewDisplay(WindowManager.VIEW_RECOND, false);
            mRecordLayout = null;
        }
    }

    public static void createTemperatureLayout(Context context) {
        if (temperatureLayout != null) {
            return;
        }
        WindowManager mWindowManager = getWindowManager(context);
        temperatureLayout = new TemperatureLayout(context);
        layoutParamsTemperature = new WindowManager.LayoutParams();
        layoutParamsTemperature.width = 600;
        layoutParamsTemperature.height = 190;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            layoutParamsTemperature.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
        } else {
            layoutParamsTemperature.type = WindowManager.LayoutParams.TYPE_PHONE;
        }
        layoutParamsTemperature.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
        layoutParamsTemperature.gravity = Gravity.LEFT | Gravity.TOP;
        layoutParamsTemperature.format = PixelFormat.TRANSPARENT;
        layoutParamsTemperature.x = 80;
        layoutParamsTemperature.y = 40;
        mWindowManager.addView(temperatureLayout, layoutParamsTemperature);
    }

    public static void removeTemperatureLayout(Context context) {
        if (temperatureLayout != null) {
            WindowManager mWindowManager = getWindowManager(context);
            mWindowManager.removeView(temperatureLayout);
            temperatureLayout.stopTimer();
            temperatureLayout = null;
            layoutParamsTemperature = null;
        }
    }

    public static void createTouchLockLayout(final Context context) {
        createTouchLockLayout(context, TouchLockView.RIGHT_MODE);
    }
    public static void createTouchLockLayout(final Context context, int position) {
        if (mTouchLockView != null) {
            return;
        }
        WindowManager mWindowManager = getWindowManager(context);
        mTouchLockView = new TouchLockView(context, position);
        layoutParamsTouchLock = new WindowManager.LayoutParams();
        layoutParamsTouchLock.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
        layoutParamsTouchLock.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParamsTouchLock.height = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParamsTouchLock.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
                | LayoutParams.FLAG_NOT_FOCUSABLE;
        layoutParamsTouchLock.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

        layoutParamsTouchLock.gravity = Gravity.LEFT | Gravity.TOP;
        layoutParamsTouchLock.format = PixelFormat.TRANSPARENT;
        mWindowManager.addView(mTouchLockView, layoutParamsTouchLock);
        //createLockViewLayout(context);

        setPctouchEnable(false);
    }

    public static void createLockViewLayout(Context context) {
        if (mLockViewLeft != null && mLockViewRight != null) {
            mLockViewLeft.refreshRun();
            mLockViewRight.refreshRun();
            return;
        }
        WindowManager mWindowManager = getWindowManager(context);
        mLockViewLeft = new TouchLockImage(context);
        mLockViewRight = new TouchLockImage(context);
        layoutParamsLockLeft = new WindowManager.LayoutParams();
        layoutParamsLockLeft.width = LayoutParams.WRAP_CONTENT;;
        layoutParamsLockLeft.height = LayoutParams.WRAP_CONTENT;;
        layoutParamsLockLeft.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
                | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
        layoutParamsLockLeft.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
        layoutParamsLockLeft.gravity = Gravity.LEFT | Gravity.CENTER;
        layoutParamsLockLeft.x = 20;
        layoutParamsLockLeft.format = PixelFormat.TRANSPARENT;
        layoutParamsLockRight= new WindowManager.LayoutParams();
        layoutParamsLockRight.width = LayoutParams.WRAP_CONTENT;;
        layoutParamsLockRight.height = LayoutParams.WRAP_CONTENT;;
        layoutParamsLockRight.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
                | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
        layoutParamsLockRight.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
        layoutParamsLockRight.gravity = Gravity.RIGHT | Gravity.CENTER;
        layoutParamsLockRight.x = 20;
        layoutParamsLockRight.format = PixelFormat.TRANSPARENT;
        mWindowManager.addView(mLockViewLeft, layoutParamsLockLeft);
        mWindowManager.addView(mLockViewRight, layoutParamsLockRight);
    }

    public static void removeLockViewLayout(Context context){
        if (mLockViewLeft != null) {
            WindowManager mWindowManager = getWindowManager(context);
            mWindowManager.removeView(mLockViewLeft);
            mLockViewLeft.removeRunnable();
            mLockViewLeft = null;
            layoutParamsLockLeft = null;
        }
        if(mLockViewRight != null){
            WindowManager mWindowManager = getWindowManager(context);
            mWindowManager.removeView(mLockViewRight);
            mLockViewRight.removeRunnable();
            mLockViewRight = null;
            layoutParamsLockRight = null;
        }
    }

    public static void removeTouchLockLayout(Context context) {
        if (mTouchLockView != null) {
            WindowManager mWindowManager = getWindowManager(context);
            mWindowManager.removeView(mTouchLockView);
            Handler handler = new Handler(Looper.getMainLooper());
            handler.post(new Runnable() {
                public void run() {
                    Toast.makeText(context,context.getString(R.string.touch_lock_isopen),Toast.LENGTH_SHORT).show();
                }
            });
            mTouchLockView = null;
            layoutParamsTouchLock = null;
            /*if(mLockViewLeft != null){
                mLockViewLeft.refreshLock();
            }
            if(mLockViewRight != null){
                mLockViewRight.refreshLock();
            }*/
            setPctouchEnable(true);
        }
    }

    /**
     * 控制第二路USB触摸开关
     * 主要针对电容屏等设备
     * @param enable 开关
     */
    private static void setPctouchEnable(boolean enable) {
        if ("kasa".equals(SystemProperties.get("persist.sys.touch.type.info", "unknown"))) {
            //todo tangyue-20221207
          /*  if(SkgTouchManager.getInstance() != null
                    && SkgSourceManager.getInstance().getCurrentSource() != SkgSourceManager.INPUT_SOURCE_ANDROID
                    && SkgSourceManager.getInstance().getCurrentSource() != SkgSourceManager.INPUT_SOURCE_ANDROID_APP){
                SkgTouchManager.getInstance().setPctouchEnable(enable);
            }*/
        }
    }


    //润屏
    public static void showBurnView2(Context context) {
        MyWindowManager.createBurnView(context);
    }

    public static void createBurnView(Context context) {
        WindowManager windowManager = getWindowManager(context);
        if (mProtectBurnView == null) {
            mProtectBurnView = new ProtectBurnView2(context);
            if (mProtectBurnViewParams == null) {
                mProtectBurnViewParams = new LayoutParams();
                mProtectBurnViewParams.width = 3840;//WindowManager.LayoutParams.MATCH_PARENT;
                mProtectBurnViewParams.height = 2160;//WindowManager.LayoutParams.MATCH_PARENT;
                mProtectBurnViewParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;;
                mProtectBurnViewParams.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_FULLSCREEN;
                mProtectBurnViewParams.gravity = Gravity.CENTER;
                mProtectBurnViewParams.format = PixelFormat.RGBA_8888;
                mProtectBurnViewParams.systemUiVisibility = SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
                mProtectBurnViewParams.setTitle("skg_protect_burn_window");
            }
            windowManager.addView(mProtectBurnView, mProtectBurnViewParams);
        }
    }

    public static void removeBurnView(Context context) {
        if (mProtectBurnView != null) {
            // 先重置状态
            mProtectBurnView.reset();
            mProtectBurnView.cancelPendingAnimations();

            // 移除视图
            WindowManager windowManager = getWindowManager(context);
            windowManager.removeView(mProtectBurnView);
            mProtectBurnView = null;

            // 重置参数
            mProtectBurnViewParams = null;
        }
    }

    public static void spotLightLongPress(Context context) {
        if (isShowSpotLight && mSpotLayout != null) {
            final WindowManager windowManager = getWindowManager(context);
            windowManager.removeView(mSpotLayout);
            isShowSpotLight = false;
            mSpotLayout = null;
        } else {
            createSpotLight1(context);
        }
    }
}
